import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author Administrator
 */
public class Circulation {
    public static void main(String[] args) {
        String[] atp = {"Rafael Nadal", "Novak Djokovic",
                "Stanislas Wawrinka",
                "David Ferrer", "Roger Federer",
                "Andy Murray", "Tomas Berdych",
                "Juan Martin Del Potro"};
        List<String> players = Arrays.asList(atp);

        // 使用 java7 遍历
        for (String palyers : players) {
            System.out.print(palyers + " ");
        }
        System.out.println();
        // 使用 lambda 表达式遍历
        System.out.println("使用 lambda 表达式遍历");
        players.forEach(player -> System.out.print(player+" "));

        // 在 Java 8 中使用双冒号操作符(double colon operator)
        players.forEach(System.out::println);

        // 排序
        System.out.println("Java7 排序");
        Collections.sort(players, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return  o1.compareTo(o2);
            }
        });
        players.forEach(System.out::println);

        // java8 排序
        System.out.println("Java8 排序");
        Collections.sort(players,(s1,s2) -> s1.compareTo(s2));
        players.forEach(System.out::println);
    }

}
